import * as cc from "cc";
import GridListView from "../../../../framework/components/scroll_view/list_view/GridListView";
import ListView, { ListViewParams } from "../../../../framework/components/scroll_view/list_view/ListView";
import { Loger } from "../../../../framework/loger/Loger";
import VCListViewDemo from "../vc/VCListViewDemo";
import { ViewBase } from './../../../../framework/view/ViewBase';

const { ccclass, property, menu } = cc._decorator;
@ccclass("ViewListViewDemo")
@menu("GameView/ViewListViewDemo")
export default class ViewListViewDemo extends ViewBase {

    protected static prefabUrl: string = "game/prefab/mvc/list_view_demo/ListViewDemo";
    public static className: string = "ViewListViewDemo"
    protected vc: VCListViewDemo = null;

    @property({ type: ListView })
    listViewTB: ListView = null;
    @property({ type: ListView })
    listViewBT: ListView = null;
    @property({ type: ListView })
    listViewLR: ListView = null;
    @property({ type: ListView })
    listViewRL: ListView = null;
    @property({ type: GridListView })
    gridView: GridListView = null;

    btnRefresh: cc.Node
    btnSetPos: cc.Node
    //生命周期：onInit(加载时只调一次)==>onOpen(每次showui时)==>onShow()==>onStart()==>onHide()==>onClose()
    /**只会在首次加载时调用一次，可以用于获取节点，绑定事件 */
    protected onInit() {
        super.onInit();
        this.btnRefresh = this.node.getChildByName("btnRefresh")
        this.setClickListener(this.btnRefresh, this.onClickRefresh, this);
        this.btnSetPos = this.node.getChildByName("btnSetPos")
        this.setClickListener(this.btnSetPos, this.onClickSetPos, this);

    }

    /**每次打开UI前，onStart前,每次呼出前赋值传参的时候用 */
    protected onOpen() {
        super.onOpen();
        this.refreshView();
    }

    /**开始动画播完 onShow之后*/
    protected onStart() {
        super.onStart();
    }

    /**关闭动画结束后 */
    protected onClose() {
        super.onClose();
    }

    /**update生命周期 */
    protected onUpdate(dt) {
    }

    onClickRefresh() {
        let params: ListViewParams = {
            arr_data: this.vc.data2,
            vc: this.vc,
            is_clean: false,
            interval: 0.1
        }
        this.listViewTB.reloadData(params);
        this.listViewBT.reloadData(params);
        this.listViewLR.reloadData(params);
        this.listViewRL.reloadData(params);
        this.gridView.reloadData(params);
        Loger.logConfig("---点击刷新---")
    }

    onClickSetPos() {
        this.listViewTB.scrollToItem(99);
        this.listViewBT.scrollToItem(1);
        this.listViewLR.scrollToItem(0);
        this.listViewRL.scrollToItem(40, 0.1);
        this.gridView.scrollToItem(40);
        Loger.logBusiness("---点击定位---", "onClickSetPos")
    }

    refreshView() {
        this.listViewTB && this.listViewTB.reloadData({
            arr_data: this.vc.data,
            vc: this.vc,
            from_index: 90,
            interval: 0.1
        }).then(() => {
            Loger.log("listViewTB load done")
        });
        this.listViewBT && this.listViewBT.reloadData({
            arr_data: this.vc.data,
            vc: this.vc,
            from_index: 98,
            interval: 0.1
        }).then(() => {
            Loger.log("listViewBT load done", this.vc.data.length)
        });
        this.listViewLR && this.listViewLR.reloadData({
            arr_data: this.vc.data,
            vc: this.vc,
            from_index: 97,
            interval: 0.1
        }).then(() => {
            Loger.log("listViewLR load done")
        });
        this.listViewRL && this.listViewRL.reloadData({
            arr_data: this.vc.data,
            vc: this.vc,
            from_index: 96,
            interval: 0.1,
        }).then(() => {
            Loger.log("listViewRL load done", JSON.stringify(this.vc.data))
        });

        this.gridView && this.gridView.reloadData({
            arr_data: this.vc.data,
            vc: this.vc,
            interval: 0.1,
            from_index: 90,
        }).then(() => {
            Loger.log("gridView load done", JSON.stringify(this.vc.data))
        });

    }

}